package com.vnp.cooking.slidingmenu;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.actionbarsherlock.app.SherlockListFragment;
import com.vnp.cooking.MainActivity;
import com.vnp.cooking.R;
import com.vnp.cooking.adapter.SlidingMenuAdapter;
import com.vnp.cooking.bean.ObjSlidingMenu;

public class ListMenu extends SherlockListFragment{
	String[] list_contents = {
		"Món ăn theo bữa",
		"Món ăn theo dịp",
		"Món ăn theo mùa"
	};
	int[] list_resource_icon = {
			R.drawable.ic_launcher, 
			R.drawable.ic_launcher, 
			R.drawable.ic_launcher
	};
	ObjSlidingMenu[] objSlidingMenus;
	
	ListView listSlidingMenu;
	SlidingMenuAdapter slidingMenuAdapter;
	
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveIntancestate) {
		View view = inflater.inflate((R.layout.list), container, false);
		return view;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
//		listSlidingMenu = (ListView) getActivity().findViewById(R.id.listmenu);
		slidingMenuAdapter = new SlidingMenuAdapter(getActivity(), createData());
		getListView().setAdapter(slidingMenuAdapter);
//		setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, list_contents));
	}

	@Override
	public void onListItemClick(ListView lv, View v, int position, long id) {
		Fragment newContent = null;
		switch (position) {
		case 0:
//			newContent = new ForMeals();
			Log.i("Test", "menu 1");
			break;
		case 1:
//			newContent = new ForOccasionDish();
			Log.i("Test", "menu 2");
			break;
		case 2:
//			newContent = new ForOriginDish();
			Log.i("Test", "menu 3");
			break;

		}
		
		if (newContent != null)
			switchFragment(newContent);
	}
	
	// the meat of switching the above fragment
		private void switchFragment(Fragment fragment) {
			if (getActivity() == null)
				return;
			
			if (getActivity() instanceof MainActivity) {
				MainActivity fca = (MainActivity) getActivity();
//				fca.switchContent(fragment);
			}
		}

	public ArrayList<ObjSlidingMenu> createData() {
		ArrayList<ObjSlidingMenu> items = new ArrayList<ObjSlidingMenu>();
		items.add(new ObjSlidingMenu(R.drawable.ic_sld001, getString(R.string.sld_theobua)));
		items.add(new ObjSlidingMenu(R.drawable.ic_sld002, getString(R.string.sld_theonguongoc)));
		items.add(new ObjSlidingMenu(R.drawable.ic_sld003, getString(R.string.sld_theondip)));
		items.add(new ObjSlidingMenu(R.drawable.ic_sld001, getString(R.string.sld_theonguyenlieu)));
		items.add(new ObjSlidingMenu(R.drawable.ic_sld002, getString(R.string.sld_theochedo)));
		return items;
	}
	
	

}
